package org.rsbot.script.randoms;

import org.rsbot.script.Random;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Camera;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.methods.NPCs;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Settings;
import org.rsbot.script.methods.Walking;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors={"Keilgo"}, name="DrillDemon", version=0.1D)
public class DrillDemon extends Random
{
  public int demonID = 2790;
  public int sign1;
  public int sign2;
  public int sign3;
  public int sign4;

  public boolean activateCondition()
  {
    return playerInArea(3167, 4822, 3159, 4818);
  }

  public int loop()
  {
    this.camera.setPitch(true);
    this.camera.setCompass('N');

    if ((getMyPlayer().isMoving()) || (getMyPlayer().getAnimation() != -1)) {
      return random(1200, 1500);
    }
    RSNPC localRSNPC = this.npcs.getNearest(new int[] { this.demonID });
    RSObject localRSObject1 = this.objects.getNearest(new int[] { 10076 });
    RSObject localRSObject2 = this.objects.getNearest(new int[] { 10077 });
    RSObject localRSObject3 = this.objects.getNearest(new int[] { 10078 });
    RSObject localRSObject4 = this.objects.getNearest(new int[] { 10079 });

    if (localRSNPC == null) {
      return -1;
    }
    myClickContinue();
    sleep(random(750, 1000));

    if (this.interfaces.get(148).isValid()) {
      switch (this.settings.getSetting(531)) {
      case 668:
        this.sign1 = 1;
        this.sign2 = 2;
        this.sign3 = 3;
        this.sign4 = 4;
        break;
      case 675:
        this.sign1 = 2;
        this.sign2 = 1;
        this.sign3 = 3;
        this.sign4 = 4;
        break;
      case 724:
        this.sign1 = 1;
        this.sign2 = 3;
        this.sign3 = 2;
        this.sign4 = 4;
        break;
      case 738:
        this.sign1 = 3;
        this.sign2 = 1;
        this.sign3 = 2;
        this.sign4 = 4;
        break;
      case 787:
        this.sign1 = 2;
        this.sign2 = 3;
        this.sign3 = 1;
        this.sign4 = 4;
        break;
      case 794:
        this.sign1 = 3;
        this.sign2 = 2;
        this.sign3 = 1;
        this.sign4 = 4;
        break;
      case 1116:
        this.sign1 = 1;
        this.sign2 = 2;
        this.sign3 = 4;
        this.sign4 = 3;
        break;
      case 1123:
        this.sign1 = 2;
        this.sign2 = 1;
        this.sign3 = 4;
        this.sign4 = 3;
        break;
      case 1228:
        this.sign1 = 1;
        this.sign2 = 4;
        this.sign3 = 2;
        this.sign4 = 3;
        break;
      case 1249:
        this.sign1 = 4;
        this.sign2 = 1;
        this.sign3 = 2;
        this.sign4 = 3;
        break;
      case 1291:
        this.sign1 = 2;
        this.sign2 = 4;
        this.sign3 = 1;
        this.sign4 = 3;
        break;
      case 1305:
        this.sign1 = 4;
        this.sign2 = 2;
        this.sign3 = 1;
        this.sign4 = 3;
        break;
      case 1620:
        this.sign1 = 1;
        this.sign2 = 3;
        this.sign3 = 4;
        this.sign4 = 2;
        break;
      case 1634:
        this.sign1 = 3;
        this.sign2 = 1;
        this.sign3 = 4;
        this.sign4 = 2;
        break;
      case 1676:
        this.sign1 = 1;
        this.sign2 = 4;
        this.sign3 = 3;
        this.sign4 = 2;
        break;
      case 1697:
        this.sign1 = 4;
        this.sign2 = 1;
        this.sign3 = 3;
        this.sign4 = 2;
        break;
      case 1802:
        this.sign1 = 3;
        this.sign2 = 4;
        this.sign3 = 1;
        this.sign4 = 2;
        break;
      case 1809:
        this.sign1 = 4;
        this.sign2 = 3;
        this.sign3 = 1;
        this.sign4 = 2;
        break;
      case 2131:
        this.sign1 = 2;
        this.sign2 = 3;
        this.sign3 = 4;
        this.sign4 = 1;
        break;
      case 2138:
        this.sign1 = 3;
        this.sign2 = 2;
        this.sign3 = 4;
        this.sign4 = 1;
        break;
      case 2187:
        this.sign1 = 2;
        this.sign2 = 4;
        this.sign3 = 3;
        this.sign4 = 1;
        break;
      case 2201:
        this.sign1 = 4;
        this.sign2 = 2;
        this.sign3 = 3;
        this.sign4 = 1;
        break;
      case 2250:
        this.sign1 = 3;
        this.sign2 = 4;
        this.sign3 = 2;
        this.sign4 = 1;
        break;
      case 2257:
        this.sign1 = 4;
        this.sign2 = 3;
        this.sign3 = 2;
        this.sign4 = 1;
      }

    }

    if (this.interfaces.getComponent(148, 1).getText().contains("jumps")) {
      if (this.sign1 == 1) {
        if (this.calc.distanceTo(new RSTile(3167, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3160, 4820), 0, 0));

          localRSObject1.doAction("Use");
        } else {
          localRSObject1.doAction("Use");
        }
        return random(1000, 1500);
      }if (this.sign2 == 1) {
        localRSObject2.doAction("Use");
        return random(1000, 1500);
      }if (this.sign3 == 1) {
        localRSObject3.doAction("Use");
        return random(1000, 1500);
      }if (this.sign4 == 1) {
        if (this.calc.distanceTo(new RSTile(3159, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3166, 4820), 0, 0));

          localRSObject4.doAction("Use");
        } else {
          localRSObject4.doAction("Use");
        }
        return random(1000, 1500);
      }
    } else if (this.interfaces.getComponent(148, 1).getText().contains("push ups"))
    {
      if (this.sign1 == 2) {
        if (this.calc.distanceTo(new RSTile(3167, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3160, 4820), 0, 0));

          localRSObject1.doAction("Use");
        } else {
          localRSObject1.doAction("Use");
        }
        return random(1000, 1500);
      }if (this.sign2 == 2) {
        localRSObject2.doAction("Use");
        return random(1000, 1500);
      }if (this.sign3 == 2) {
        localRSObject3.doAction("Use");
        return random(1000, 1500);
      }if (this.sign4 == 2) {
        if (this.calc.distanceTo(new RSTile(3159, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3166, 4820), 0, 0));

          localRSObject4.doAction("Use");
        } else {
          localRSObject4.doAction("Use");
        }
        return random(1000, 1500);
      }
    } else if (this.interfaces.getComponent(148, 1).getText().contains("sit ups"))
    {
      if (this.sign1 == 3) {
        if (this.calc.distanceTo(new RSTile(3167, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3160, 4820), 0, 0));

          localRSObject1.doAction("Use");
        } else {
          localRSObject1.doAction("Use");
        }
        return random(1000, 1500);
      }if (this.sign2 == 3) {
        localRSObject2.doAction("Use");
        return random(1000, 1500);
      }if (this.sign3 == 3) {
        localRSObject3.doAction("Use");
        return random(1000, 1500);
      }if (this.sign4 == 3) {
        if (this.calc.distanceTo(new RSTile(3159, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3166, 4820), 0, 0));

          localRSObject4.doAction("Use");
        } else {
          localRSObject4.doAction("Use");
        }
        return random(1000, 1500);
      }
    } else if (this.interfaces.getComponent(148, 1).getText().contains("jog on")) {
      if (this.sign1 == 4) {
        if (this.calc.distanceTo(new RSTile(3167, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3160, 4820), 0, 0));

          localRSObject1.doAction("Use");
        } else {
          localRSObject1.doAction("Use");
        }
        return random(1000, 1500);
      }if (this.sign2 == 4) {
        localRSObject2.doAction("Use");
        return random(1000, 1500);
      }if (this.sign3 == 4) {
        localRSObject3.doAction("Use");
        return random(1000, 1500);
      }if (this.sign4 == 4) {
        if (this.calc.distanceTo(new RSTile(3159, 4820)) < 2) {
          this.walking.walkTileMM(this.walking.randomize(new RSTile(3166, 4820), 0, 0));

          localRSObject4.doAction("Use");
        } else {
          localRSObject4.doAction("Use");
        }
        return random(1000, 1500);
      }
    }

    if (!myClickContinue()) {
      localRSNPC.doAction("Talk-to");
    }

    return random(1000, 1500);
  }

  public boolean myClickContinue() {
    sleep(random(800, 1000));
    return (this.interfaces.getComponent(243, 7).doClick()) || (this.interfaces.getComponent(241, 5).doClick()) || (this.interfaces.getComponent(242, 6).doClick()) || (this.interfaces.getComponent(244, 8).doClick()) || (this.interfaces.getComponent(64, 5).doClick());
  }

  public boolean playerInArea(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    int i = getMyPlayer().getLocation().getX();
    int j = getMyPlayer().getLocation().getY();

    return (i >= paramInt3) && (i <= paramInt1) && (j >= paramInt4) && (j <= paramInt2);
  }
}